package com.javasm.gg.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.gg.GoodsTypesService;
import com.javasm.gg.dao.GoodsTypeDao;
import com.javasm.gg.GoodsType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeDao,GoodsType> implements GoodsTypesService {

    @Override
    public String getnextId(String pid) {
        QueryWrapper w  =new QueryWrapper();
        w.select("max(id) as id");
        w.eq("pid",pid);
        GoodsType one = getOne(w);
        if(one==null){
            if("-1".equals(pid))return "10";
            else return pid+"01";
        }
        return String.valueOf(Long.parseLong(one.getId())+1);
    }

    @Transactional
    @Override
    public boolean setChooseBrands2GoodsType(String goodsTypeId, Integer[] brandIds) {
        this.baseMapper.removeChooseBrand2ByGoodsTypeId(goodsTypeId);
        int r = this.baseMapper.setChooseBrands2GoodsType(goodsTypeId,brandIds);
        return r==brandIds.length;
    }
}
